package com.xu.ThrreadPool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

/**
 * 线程工厂的示例
 */
public class ThreadPoolDemo3 {

    public static void main(String[] args) {

        //1.创建线程工厂
        ThreadFactory threadFactory = r -> {
            Thread thread = new Thread(r);
            //设置线程命名规则
            thread.setName("我的线程："+r.hashCode());
            //设置线程的优先级
            thread.setPriority(Thread.MAX_PRIORITY);
            return thread;
        };

        ExecutorService executorService = Executors.newFixedThreadPool(5, threadFactory);
        for (int i = 0; i < 10; i++) {
            executorService.submit(()->{
                System.out.println("线程池开始执行了："+Thread.currentThread().getName());
            });

        }
    }
}
